<div id="tabs">
	<ul>
        <li><?php echo $this->Html->link(__('Xem chỉ tiêu', true), array('controller' => 'chitieunvs', 'action' => 'hienchitieuthang',$kehoach_id)); ?> </li>
        <li id="current"><?php echo $this->Html->link(__('Bổ sung chỉ tiêu', true), array('controller'=>'chitieunvs','action' => 'chonchitieubs',$kehoach_id,2));?></li>
        <li><?php echo $this->Html->link(__('Các thời gian giao khác', true), array('controller'=>'kehoaches','action' => 'giaochitieu',$this->Session->read('cur_dv')));?></li>
	</ul>
</div>
<script type="text/javascript">
$(document).ready(function()
				{
				$(".checkbox").click(function(){
												if ($(this).is(":checked"))
												{
													
													$val=parseInt($("#checknum").val(),10);
													$val=$val+1;
													$("#checknum").val($val);
													id=$(this).attr('id');
													$('#tbl td#'+id).css('background-color','#CCFFCC');

												}
												else
												{
													$val=parseInt($("#checknum").val(),10);
													$val=$val-1;
													$("#checknum").val($val);
													id=$(this).attr('id');
													$('#tbl td#'+id).css('background-color','');
												}
												});
				$("#selectall").click(function(){
													$(".checkbox").prop('checked',true);
													$('#tbl td').css('background-color','#CCFFCC');
												});
				$("#unselectall").click(function(){
					$(".checkbox").prop('checked',false);
					$('#tbl td').css('background-color','');
				});
				});
				
	function validate()
	{
		$checked=0;
		$numpro=parseInt($("#countcheck").val(),10);
		$("input:checkbox").each(function(){
											if ($(this).is(":checked"))
													$checked++;
											});
		if ($checked==0)
		{
			alert("Bạn chưa chọn sản phẩm nào");
			return false;			
		}
		else
			return true;
	}
</script>

<div class="index">

<fieldset>
<legend>Chọn Chỉ Tiêu</legend>
<?php
	if(empty($hanghoas))
	{
		echo "<h2>Không còn sản phẩm để bổ xung</h2>";
	}
	else
	{
	echo $this->Form->create('Chitieunv', array('url'=>array('controller'=>'chitieunvs','action' => 'themchitieu',$kehoach_id,2),'type'=>'post','onsubmit'=>'return validate()'));
		echo $form->hidden('checknum',array('value'=>"0",'id'=>'checknum'));
		echo $form->hidden('countcheckhh',array('value'=>count($hanghoas),'id'=>'countcheckhh'));
		echo $form->hidden('countchecknv',array('value'=>count($nhanviens),'id'=>'countcheckhh'));
		$counthh = count($hanghoas);
		echo "<table id='tbl'>";
		$i=0;
		foreach ($hanghoas as $hh_id => $tenhh):
			if ($i%2==0)
				echo "<tr>";
			echo "<td class='td' id='checkboxhh".$i."'>".$form->input('checkboxhh'.$i,array('class'=>'checkbox','type'=>'checkbox','id'=>'checkboxhh'.$i,'value'=>$hh_id,'hidden'=>False,'label'=>$tenhh));
			echo $form->hidden('',array('value'=>$tenhh,'name'=>'data[Chitieunv][hh]['.$hh_id.']'))."</td>";
			if ($i%2!=0)
				echo "</tr>";
			$i++;
		endforeach;
		echo "</table>";
?>
<a href='#' id='selectall'>Chọn Tất Cả</a> / <a href='#' id='unselectall'>Bỏ Chọn Tất Cả</a>
</fieldset>
<?php
	$i=0;
	foreach ($nhanviens as $nv_id =>$tennv):
		echo $form->hidden($nv_id,array('value'=>$tennv));
		echo $form->hidden('checkboxnv'.$i,array('value'=>$nv_id));
		$i++;
	endforeach;
?>

<?php echo $this->Form->end('Lập Chỉ Tiêu',false);
	}?>

</div>